package com.sx.code.controller;

import com.sx.code.service.CodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author shengx
 * @date 2020/5/10 21:05
 */
@RestController
@RequestMapping("/code")
public class CodeController {
    @Autowired
    private CodeService codeService;

    /**
     * ⽣成验证码并发送到对应邮箱，成功true，失败false
     * @param email
     * @return
     */
    @GetMapping("/create/{email}")
    public Boolean create(@PathVariable String email){
        System.out.println("email:" + email);
        return codeService.createCode(email);
    }

    /**
     * 校验验证码是否正确，0正确1错误2超时
     * @param email
     * @param code
     * @return
     */
    @GetMapping("/validate/{email}/{code}")
    public Integer validate(@PathVariable String email, @PathVariable String code){
        System.out.println("email:" + email +  " code:" + code);
        return codeService.checkCode(email, code);
    }
}
